package com.ggh.jinjilive.dialog;

import android.content.Context;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.cy.dialog.BaseDialog;
import com.ggh.jinjilive.R;
import com.ggh.jinjilive.dialog.adapter.OnlineAdapter;
import com.ggh.jinjilive.listener.AddItemOnClickListener;
import com.ggh.jinjilive.listener.AddOnClickListener;
import com.ggh.jinjilive.views.live.pk.commondef.AnchorInfo;

import java.util.List;

public class OnlineDialog extends BaseDialog {
    //在线主播
    private RecyclerView rv_online;
    //在线主播适配器
    private OnlineAdapter onlineAdapter;
    public OnlineDialog(Context context) {
        super(context);
    }

    public OnlineDialog(Context context, int themeResId) {
        super(context, themeResId);

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        contentView(R.layout.dialog_list_online);
        canceledOnTouchOutside(true);
        gravity(Gravity.BOTTOM);
        animType(BaseDialog.AnimInType.BOTTOM);
        //关闭
        findViewById(R.id.ll_Shut_down).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                dismiss();
            }
        });

        rv_online = findViewById(R.id.rv_online);
        onlineAdapter = new OnlineAdapter();
        onlineAdapter.setAddItemOnClickListener(new AddItemOnClickListener() {
            @Override
            public void onSkipClicked(int position, Object mObject) {
                if(null != addItemOnClickListener){
                    addItemOnClickListener.onSkipClicked(position,mObject);
                }
            }
        });
        rv_online.setLayoutManager(new LinearLayoutManager(getContext()));
        rv_online.setAdapter(onlineAdapter);
    }

    /**
     * 在线数据
     * @param anchorInfoList
     */
    public void setAdd(List<AnchorInfo> anchorInfoList){
        if(null != onlineAdapter){
            onlineAdapter.setAdd(anchorInfoList);
        }
    }

    private AddItemOnClickListener addItemOnClickListener;
    public void setAddItemOnClickListener(AddItemOnClickListener addItemOnClickListener){
        this.addItemOnClickListener = addItemOnClickListener;
    }


    @Override
    public void show() {
        super.show();
        Window window = getWindow();
        //设置弹出位置
        window.setGravity(Gravity.BOTTOM);
        //设置对话框大小
        window.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
    }
}
